<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div class="box">
    <p class="text">这是一段文本</p>
  </div>
  <!-- <button onclick="addElementForBox()">addElement</button>
  <button onclick="addChildElement()">addChildElement</button> -->
  <script>
    const box = document.getElementsByClassName('box')[0]
    const p = document.getElementsByClassName('text')[0]
    const observer = new MutationObserver((MutationRecord) => {
      console.log(MutationRecord)
    })
    observer.observe(box, {
      childList: true,
      subtree: true,
      attributeOldValue: true,
      characterData: true
    })
    box.className = 'will'
    box.className = 'hehuan'
    box.className = 'vue'
  </script>
</body>

</html>
